#include "../../../../mac/mac_indir.h"

int8 init()
{
    return mac_indir_init();
}

int8 alloc_addr64(uint64 addr, uint8 dsn)
{
    uint8 r = MAC_OK;
    mac_indir_t *m;

    m = mac_indir_alloc();
    if (m == NULL) {
        return MAC_ERR;
    }

    (m->addr).mode = ADDR_64_M;
    (m->addr).a.addr64 = addr;
    m->dsn = dsn;

    return MAC_OK;
}

int8 alloc_addr16(uint16 addr, uint8 dsn)
{
    uint8 r = MAC_OK;
    mac_indir_t *m;

    m = mac_indir_alloc();
    if (m == NULL) {
        return MAC_ERR;
    }

    (m->addr).mode = ADDR_16_M;
    (m->addr).a.addr16 = addr;
    m->dsn = dsn;

    return MAC_OK;
}

int8 _free(uint8 dsn)
{
    return mac_indir_free(dsn);
}

int8 find_addr16(uint16 addr16)
{
    addr_t addr;
    mac_indir_t *m;

    addr.mode = ADDR_16_M;
    addr.a.addr16 = addr16;

    m = mac_indir_find(&addr);
    if (m == NULL) {
        return MAC_ERR;
    } else {
        return MAC_OK;
    }
}

int8 find_addr64(uint64 addr64)
{
    addr_t addr;
    mac_indir_t *m;

    addr.mode = ADDR_64_M;
    addr.a.addr64 = addr64;

    m = mac_indir_find(&addr);
    if (m == NULL) {
        return MAC_ERR;
    } else {
        return MAC_OK;
    }
}


